<template>
	<view class="content">
		<template v-if="hsjcList.length > 0">
			<view v-for="item in hsjcList" :key="item.id" class="every-hsjc"
				:class="item.jcResultCode == 'yang' ? 'red-bg' : item.jcResultCode == 'yin' ? 'green-bg' : '' ">
				<view class="hsjc-info-list">
					<view style="font-weight: bold;">{{item.name}}</view>
				</view>
				<view class="hsjc-info-list">
					<view>检测时间：{{item.jianceTime}}</view>
				</view>
				<view class="hsjc-info-list">
					<view>报告时间：{{item.reportTime}}</view>
				</view>
				<view class="hsjc-info-list">
					<view>检测点：{{item.jcdName}}</view>
					<view>报告结果：{{(!item.jcResultName || item.jcResultName == "-") ? "暂无结果" : item.jcResultName}}</view>
				</view>
			</view>
		</template>
		<view v-else class="no-data">暂无数据~</view>
	</view>
</template>

<script>
	let me;
	import funcs from "@/static/js/func.js"
	export default {
		data() {
			return {
				hsjcList: [],
			};
		},
		onShow() {
			this.gethsjcList()
		},
		onLoad() {
			me = this;
		},
		methods: {
			/**
			 * 查询核酸检测点列表
			 */
			gethsjcList() {
				uni.showLoading({
					title: "加载中"
				})
				me.$api.requestTask("/hsjcManage/mobileUserHsjcList", {
					sfz: uni.getStorageSync("userSfz"),
					page: 1,
					size: 1000
				}, res => {
					uni.hideLoading()
					if (res.code == "200") {
						console.log("查询结果", res.data);
						me.hsjcList = res.data.map(item=> {
							return{
								...item,
								jianceTime: item.jianceTime ? item.jianceTime.split(".000")[0].replace("T", " ") : "--",
								reportTime: item.reportTime ? item.reportTime.split(".000")[0].replace("T", " ") : "--",
							}
						});
					} else if (res.msg == "token无效" || res.msg == "请先登录") {
						uni.clearStorageSync();
						uni.switchTab({
							url: "/pages/tabbar/tabbar-4/tabbar-4"
						})
					} else {
						funcs.showModalTips(res.msg || "查询失败，请稍后再试")
					}
				}, err => {
					uni.hideLoading()
					funcs.showModalTips("对不起，系统错误，请稍后再试")
				})
			},
			handleCall(item) {
				uni.makePhoneCall({
					phoneNumber: item.phone
				})
			}
		}
	};
</script>

<style lang="scss" scoped>
	.content {
		padding: 24rpx;

		.every-hsjc {
			padding: 24rpx;

			&:not(:first-child) {
				margin-top: 24rpx;
			}

			border: 1px solid #ccc;
			border-radius: 8rpx;

			.hsjc-info-list {
				display: flex;
				justify-content: space-between;
				line-height: 1.6em;

				/deep/.iconfont {
					span {
						padding-left: 16rpx;
					}
				}
			}
		}
		.red-bg {
			background-color: rgba(240, 106, 72, .5);
		}
		.green-bg {
			background-color: rgba(72, 240, 108, .5);
		}

		.no-data {
			text-align: center;
			margin-top: 20vh;
		}
	}
</style>